import { couponApi} from './api';
import { Toast } from 'antd-mobile';
import {timeBuyIndex} from "../timeBuy/api";



export default {
    namespace: 'couponList',
    state: {
        couponList:[],
        hasMore:true,
    },
    reducers:{
        save(state, { data }) {
            return { ...state, ...data };
        },
    },
    effects: {
        *CouponEFF({ obj}, { put, call }) {
            Toast.loading('加载中...', 3);
            const result = yield call(couponApi, obj);
            if ( result.code == 200 ) {
                if( result.ret !='' ){
                    yield put({ type: 'save', data: {couponList: result.ret.list || [],pageSize:result.ret.pageSize} });
                    Toast.hide();
                }else {
                    yield put({ type: 'save', data: { hasMore: false }});
                }
                return { r:true };
            } else {

            }
        },

    },
    subscriptions: {
        setup({ dispatch, history }) {
            return history.listen(({ pathname, query }) => {
                if (pathname == '/couponList') {
                    // dispatch({ type: 'CouponEFF' });
                }
            });
        },
    },
};